﻿using System;
using System.Windows.Forms;
using Business;
using Business.Entity.Sistema.Terminal;
using Business.Entity.Sistema.Terminal.ECF;
using Business.Forms;

namespace FuncoesAdministrativas
{
    public partial class FormConfTerminal : FormDefault
    {
        public FormConfTerminal()
        {
            InitializeComponent();

        }

        private void confTerminalBindingSource_BindingComplete(object sender, BindingCompleteEventArgs e)
        {

            VerificaSituacaoTabs();
        }

        private void VerificaSituacaoTabs()
        {
            var current = (ConfTerminal)confTerminalBindingSource.Current;
            if (ckbAtivo.Checked &&
                (ckbLocadoraAtivo.Checked || ckbMerceariaAtivo.Checked || ckbRestauranteAtivo.Checked) &&
                current != null)
            {
                tabConfEcf.Enabled = true;
                tabConfTef.Enabled = true;

                if (current.ConfiguracaoEcf == null)
                {
                    current.ConfiguracaoEcf = new ConfiguracaoEcf();
                }
                if (current.ConfiguracaoTef == null)
                {
                    current.ConfiguracaoTef = new ConfiguracaoTef();
                }

            }
            else
            {
                tabConfEcf.Enabled = false;
                tabConfTef.Enabled = false;

            }
        }




        private void merceariaAtivoCheckEdit_CheckedChanged(object sender, EventArgs e)
        {
            VerificaSituacaoTabs();
        }

        private void cmdCancelar_Click(object sender, EventArgs e)
        {
            confTerminalBindingSource.Clear();
        }

        private void m_Click(object sender, EventArgs e)
        {
            confTerminalBindingSource.EndEdit();
            var t = (ConfTerminal)confTerminalBindingSource.Current;
            ConfTerminalRepository.Save(t);
            confTerminalBindingSource.Clear();
        }

        private void cmdConfigurarPdv_Click(object sender, EventArgs e)
        {
            ((ConfTerminal)confTerminalBindingSource.Current).ConfiguracaoEcf = new ConfiguracaoEcf();
            ((ConfTerminal)confTerminalBindingSource.Current).ConfiguracaoTef = new ConfiguracaoTef();
            tabConfEcf.Enabled = true;
            tabConfTef.Enabled = true;
        }
    }
}
